<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('修改栏目')" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-cloumn-edit" th:object="${sysCloumn}">
            <input name="id" th:field="*{id}" type="hidden">
            <div class="form-group">    
                <label class="col-sm-3 control-label">栏目名称：</label>
                <div class="col-sm-8">
                    <input name="name" th:field="*{name}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">栏目状态：</label>
                    <div class="col-sm-8">
                        <label class="toggle-switch switch-solid">
                            <input  type="checkbox"   id="status" th:checked="${sysCloumn.status == 0 ? true : false}">
                            <span></span>
                        </label>
                    </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">上级栏目:</label>
                <div class="col-sm-8">
                    <input id="option"  type="text" th:value="*{pid}" style="display: none">
                    <select id="post" class="form-control" >
                      <!--  <option value="0">一级栏目</option>-->
                        <option  th:each="cloumn:${cloumns}" th:value="${cloumn.id}" th:text="${cloumn.name}"  th:field="*{pid}" ></option>
                    </select>
                </div>
            </div>
           <!-- <div class="form-group">
                <label class="col-sm-3 control-label">专题图片：</label>
                <div class="col-sm-8">
                    <input type="file" id="files" accept="image/gif,image/jpeg,image/jpg,image/png,image/svg"  >
                    <input  id="filesurl"  name="url"  type="hidden" >
                    <img th:src="*{url}" alt="" id="img" style="width:300px;height:200px">
                    <div id="imgList" style="margin-top:10px"></div>
                </div>
            </div>-->
            <div class="form-group">
                <label class="col-sm-3 control-label">排序：</label>
                <div class="col-sm-8">
                    <input name="sortpath" class="form-control" type="number" th:field="*{sortpath}"required>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <script type="text/javascript">
        $(function () {
            if($("#option").val() == 0){
                $("#post").val("一级栏目");
            }
        })
        var prefix = ctx + "system/cloumn";
        $("#form-cloumn-edit").validate({
            focusCleanup: true
        });
        $("#files").on("change", function() {
            var data = new FormData();
            data.append("file", this.files[0]);
            $.ajax({
                type: "POST",
                url: ctx + "common/upload",
                data: data,
                cache: false,
                contentType: false,
                processData: false,
                dataType: 'json',
                async:false,
                success: function(result) {
                    console.log(result)
                    if (result.code == web_status.SUCCESS) {
                        var url = result.url;
                        console.log(typeof(url))
                        $("#filesurl").val(url)
                        $("#img").attr("src",url);
                    } else {
                        $.modal.alertError(result.msg);
                    }
                },
                error: function(error) {
                    $.modal.alertWarning("图片上传失败。");
                }
            });
        })
        function submitHandler() {
            if ($.validate.form()) {
                var pid = $.form.selectSelects("post");
                var data = $("#form-cloumn-edit").serializeArray();
                var status = $("input[id='status']").is(':checked') == true ? 0 : 1;
                data.push({"name": "status", "value": status});
                data.push({"name": "pid", "value":pid});
                $.operate.save(prefix + "/edit",data);
            }
        }
    </script>
</body>
</html>